var interfaceCombox;
var interfaceWin;
var showW;
function interfaceImport(type) {

	var interfaceStore = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : 'ExeclCustomize!queryInterfaceMasterByCondition.action?typeId='
					+ type
		}),
		reader : new Ext.data.JsonReader({
					root : 'publicInteface.result',
					totalProperty : 'publicInteface.totalCount'
				}, [{
							name : 'exInterfaceId',
							mapping : "exInterfaceId"
						}, {
							name : 'exPublicType',
							mapping : "exPublicType"
						}, {
							name : 'exName',
							mapping : "exName"
						}, {
							name : 'exClassId',
							mapping : "exClassId"
						}])
	});

	interfaceStore.load();

	interfaceCombox = new Ext.form.ComboBox({
				store : interfaceStore,
				valueField : "exInterfaceId",
				displayField : "exName",
				fieldLabel : '导入接口',
				hiddenName : 'payClass.day_shift',
				id : 'interfaceComboxForImport',
				anchor : '90%',
				mode : 'local',
				allowBlank : false,
				emptyText : '请选择导入接口',
				triggerAction : 'all',
				editable : false
			});

	interfaceCombox.on('select', function() {
		var cmbVale = interfaceCombox.getValue();
		if (type == 1015 || type == 1017) {
			Ext.Ajax.request({
				url : 'ExeclCustomize!payClassAndSocialValid.action',
				method : 'post',
				params : {
					id : cmbVale,
					type : type
				},
				success : function(response, result) {
					var responseTextVale = Ext.util.JSON
							.decode(response.responseText);
					var payclassList = responseTextVale.list;
					if (payclassList.length > 0) {
						var str = '';
						for (var index = 0; index < payclassList.length; index++) {
							str += payclassList[index].NAME;
							str += '，';
						}
						Ext.Msg.show({
									title : '提示',
									msg : '接口字段 “'
											+ str.substring(0, str.length - 1)
											+ '” 定义无效，请修改',
									buttons : Ext.MessageBox.OK
								});
						Ext.getCmp('nextButton').setDisabled(true);
						return;
					}
					Ext.getCmp('nextButton').setDisabled(false);
				}
			});
		} else if (type == 1013) {
			Ext.getCmp('nextButton').setDisabled(false);
		}
	});

	var interfacePanel = new Ext.form.FormPanel({
				anchor : '100%',
				frame : true,
				hideLables : false,
				height : 130,
				id : 'interfacePanel',
				buttonAlign : 'center',
				bodyStyle : 'padding:5px 5px 0',
				items : [{
							xtype : 'hidden',
							name : '_importname',
							id : '_importname'
						}, interfaceCombox]
			})

	interfaceWin = new Ext.Window({
		closable : true,
		draggable : true,
		region : 'center',
		title : '导入接口选择',
		width : 400,
		height : 150,
		buttonAlign : 'center',
		plain : true,
		items : [interfacePanel],
		buttons : [{
			text : '下  一  步',
			id : 'nextButton',
			disabled : true,
			handler : function() {
				var exInterfaceId = interfaceCombox.getValue();
				if (null == exInterfaceId || "" == exInterfaceId) {
					Ext.MessageBox.show({
								title : '提示',
								msg : '请选择接口',
								buttons : Ext.MessageBox.OK
							});
				} else {

					/**
					 * 根据excel接口类别的不同去不同的action获取数据 1、雇员信息
					 */

					if (type == 1013) {
						var index = interfaceStore
								.find(
										Ext.getCmp('interfaceComboxForImport').valueField,
										interfaceCombox.getValue());
						var classid = interfaceStore.getAt(index)
								.get('exClassId');
						var interfaceId = interfaceStore.getAt(index)
								.get('exInterfaceId');
						showW = new Ext.Window({
									width : 400,
									height : 150,
									title : '上传文件',
									id : 'showW',
									items : [getUpldPanel(
											'Fileupload!uploadFile.action',
											'GetAllPbEmploy!importByXls.action',
											interfaceId, classid, 1013)]
								})
					}
					/**
					 * 2、薪资类别
					 */
					else if (type == 1015) {
						var index = interfaceStore
								.find(
										Ext.getCmp('interfaceComboxForImport').valueField,
										interfaceCombox.getValue());
						var classid = interfaceStore.getAt(index)
								.get('exClassId');
						var interfaceId = interfaceStore.getAt(index)
								.get('exInterfaceId');
						showW = new Ext.Window({
									width : 400,
									height : 150,
									id : 'showW',
									title : '上传文件',
									items : [getUpldPanel(
											'Fileupload!uploadFile.action',
											'GetAllPbEmploy!impSo.action',
											interfaceId, classid, 1015)]
								})
					}
					/**
					 * 3、社保项目
					 */
					else if (type == 1017) {
						var index = interfaceStore
								.find(
										Ext.getCmp('interfaceComboxForImport').valueField,
										interfaceCombox.getValue());
						var classid = interfaceStore.getAt(index)
								.get('exClassId');
						var interfaceId = interfaceStore.getAt(index)
								.get('exInterfaceId');
						showW = new Ext.Window({
									width : 400,
									height : 150,
									id : 'showW',
									title : '上传文件',
									items : [getUpldPanel(
											'Fileupload!uploadFile.action',
											'GetAllPbEmploy!importSocial.action',
											interfaceId, classid, 1017)]
								})
					}
					showW.show();
					interfaceWin.hide();
				}

			}
		}],
		listeners : {
			"beforedestroy" : function(obj) {
				return false;
			},
			"beforeshow" : function(obj) {
				return true;
			}
		}
	});
	return interfaceWin;
};
